<?php

import ( 'classes.acct.CTKHO' );

class CTKHODAO extends DAO {

	function &getCTKHO_view($query, $paramArray, $rangeInfo) {
		$result =& $this->retrieveRange($query, $paramArray, $rangeInfo);

		//$result = & $this->retrieve ( $query, $paramArray );
		//$returner = new DAOResultFactory($result, $this, '_returnChuyengiaFromRow');
		//return $returner;

		$returner = new DAOResultFactory ( $result, $this, '_returnCTKHO_view_FromRow' );
		return $returner;

	}



	function &_returnCTKHO_view_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO ->setidphieu($row['idphieu']);
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->setmakhox($row['makhox']);
		$CTKHO->setmadvno($row['madvno']);
		$CTKHO->setmavt($row['mavt']);
		$CTKHO->setsl($row['sl']);
		$CTKHO->setdgb($row['dgb']);
		$CTKHO->setsotienvnb($row['sotienvnb']);
		return $CTKHO;

	}


	function &getCTKHO_viewNT($query, $paramArray) {
		//echo $query;
		$result = & $this->retrieve ( $query, $paramArray );

		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKHO_viewNT_FromRow' );
		
		$sections = $returner;
		$i = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {
			$sections [$i] ['idphieu'] = $section->getidphieu ();
			$sections [$i] ['ngct'] = $section->getngct ();
			$sections [$i] ['soct'] = $section->getsoct ();
			$sections [$i] ['diengiai'] = $section->getdiengiai ();
			$sections [$i] ['tkdu'] = $section->gettkdu ();
			$sections [$i] ['macttkdu'] = $section->getmacttkdu ();
			$sections [$i] ['tk'] = $section->gettk();
			$sections [$i] ['sotienvn'] = $section->getsotienvn ();
			$sections [$i] ['sotiennt'] = $section->getsotiennt ();
			$i += 1;
			unset ( $section );
		}
		return $sections;
	}

	function &_returnCTKHO_viewNT_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO ->setidphieu($row['idphieu']);
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->setdiengiai($row['diengiai']);
		$CTKHO->settk($row['tk']);
		$CTKHO->settkdu($row['tkdu']);
		$CTKHO->setmacttkdu($row['macttkdu']);
		$CTKHO->setsotienvn($row['sotienvn']);
		$CTKHO->setsotiennt($row['sotiennt']);
		return $CTKHO;
	}


	function &getCTKHO_edit($query) {
		$result = & $this->retrieve( $query );

		
		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKHO_edit_FromRow' );
		
		

		$sections = $returner;
		$i = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {

			$sections [$i] ['soct'] = $section->getsoct ();
			$sections [$i] ['sosr'] = $section->getsosr ();
			$sections [$i] ['ngct'] = $section->getngct ();
			$sections [$i] ['diengiai'] = $section->getdiengiai ();

			$sections [$i] ['makhox'] = $section->getmakhox ();
			$sections [$i] ['madvno'] = $section->getmadvno ();
			$sections [$i] ['tendvno'] = $section->gettendvno ();
			$sections [$i] ['msthueno'] = $section->getmsthueno ();

			$sections [$i] ['diachino'] = $section->getdiachino ();
			$sections [$i] ['tk_dv'] = $section->gettk_dv ();
			$sections [$i] ['tk_thue'] = $section->gettk_thue ();
			$sections [$i] ['mavt'] = $section->getmavt ();

			$sections [$i] ['solo'] = $section->getsolo ();
			$sections [$i] ['handung'] = $section->gethandung ();
			$sections [$i] ['sl'] = $section->getsl ();
			$sections [$i] ['dgb'] = $section->getdgb ();

			$sections [$i] ['sotienvnb'] = $section->getsotienvnb ();
			$sections [$i] ['tlck'] = $section->gettlck ();
			$sections [$i] ['tk_ck'] = $section->gettk_ck ();
			$sections [$i] ['tk_dt'] = $section->gettk_dt ();

			
			$i += 1;
			unset ( $section );
		}
		return $sections;
	}

	function &_returnCTKHO_edit_FromRow(&$row) {


		$CTKHO = new CTKHO();
		$CTKHO ->setidphieu($row['idphieu']);
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setsosr($row['sosr']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->setdiengiai($row['diengiai']);
		$CTKHO->setmakhox($row['makhox']);
		$CTKHO->setmadvno($row['madvno']);
		$CTKHO->settendvno($row['tendvno']);
		$CTKHO->setmsthueno($row['msthueno']);
		$CTKHO->setdiachino($row['diachino']);
		$CTKHO->settk_dv($row['tk_dv']);
		$CTKHO->settk_thue($row['tk_thue']);
		$CTKHO->setmavt($row['mavt']);
		$CTKHO->setsolo($row['solo']);
		$CTKHO->sethandung($row['handung']);
		$CTKHO->setsl($row['sl']);
		$CTKHO->setdgb($row['dgb']);
		$CTKHO->setsotienvnb($row['sotienvnb']);
		$CTKHO->settlck($row['tlck']);
		$CTKHO->settk_ck($row['tk_ck']);
		$CTKHO->settk_dt($row['tk_dt']);
		return $CTKHO;

	}
function &getBCTC_SDDK($journalid, $nam) {
		$sections = $returner;
		$query = "SELECT matk, dknovn, dkcovn  FROM SDTK" .$journalid. $nam ;
		$result = & $this->retrieve ( $query );
		$returner = array();
		while (!$result->EOF) {
				$row = $result->GetRowAssoc(false);
				$returner[$row['matk']]['dknovn'] = $row['dknovn'];
				$returner[$row['matk']]['dkcovn'] = $row['dkcovn'];

				$result->moveNext();
		}
		$result->Close();
		unset($result);
		return $returner;

}

function &getBCTC_PS($journalid, $nam, $ngay1, $ngay2, $ectkt, $eCTKHO) {
	if ($ectkt && $eCTKHO)
	{
	$query = 	
	   "SELECT @s:=@s+1 stt, a.idphieu,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."')
	union
	SELECT @s:=@s+1 stt, a.idphieu, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') 
	   Order by ngct, soct, id";
	}
	elseif ($ectkt && !$eCTKHO)
		$query = 	
	   "SELECT @s:=@s+1 stt, '".$tk."' as tk,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."')   Order by ngct, soct, id";
	  else if (!$ectkt && $eCTKHO)
	$query = 	
	   " SELECT @s:=@s+1 stt, '".$tk."' as tk, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') Order by ngct, soct, id";
	////
		$result = & $this->retrieve ( $query );

		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKHO_socai_FromRow' );

		$sections = $returner;
		$k = 0;
		while ( ($section = & $sectionsIterator->next ()) ) {
				$tkno = $section->gettkno ();
				$tkco = $section->gettkco ();
				$sotien = $section->getsotienvn ();
				
				$sections [$tkno] ['psnovn'] = $sections [$tkno] ['psnovn']+ $sotien;
				$sections [$tkco] ['pscovn'] = $sections [$tkco] ['pscovn']+ $sotien;
				unset ( $section );
		}

		return $sections;
		
	}

function &getCTKHO_STHTCG($noco, $journalid, $nam, $ngay1, $ngay2, $tk, $ectkt, $eCTKHO) {
	if ($ectkt && $eCTKHO)
	{
	$query = 	
	   "SELECT @s:=@s+1 stt, a.idphieu,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (a.tk like '".$tk."%'  or b.tkdu like '".$tk."%' )
	union
	SELECT @s:=@s+1 stt, a.idphieu, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (b.tkno like '".$tk."%'  or b.tkco like '".$tk."%' )
	   Order by ngct, soct, id";
	}
	elseif ($ectkt && !$eCTKHO)
		$query = 	
	   "SELECT @s:=@s+1 stt, '".$tk."' as tk,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (a.tk like '".$tk."%'  or b.tkdu like '".$tk."%' )   Order by ngct, soct, id";
	  else if (!$ectkt && $eCTKHO)
	$query = 	
	   " SELECT @s:=@s+1 stt, '".$tk."' as tk, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (b.tkno like '".$tk."%'  or b.tkco like '".$tk."%' )
	   Order by ngct, soct, id";
	////
		$result = & $this->retrieve ( $query );

		$sectionsIterator = new DAOResultFactory ( $result, $this, '_returnCTKHO_socai_FromRow' );

		$sections = $returner;
		$k = 0;
		if ($noco == "NO")
			while ( ($section = & $sectionsIterator->next ()) ) {
				$tkno = $section->gettkno ();
				if (strpos($tkno, $tk) ===0)
				{
					$i = $section->getidphieu ();	
					$tkco = $section->gettkco ();
					$sotien = $section->getsotienvn ();
					if (!in_array($tkco, $sections ['tk']))
						{
						$sections ['tk'][$k] =$tkco;
						$k += 1;
						}

					
					$sections [$i] ['ngct'] = $section->getngct ();
					$sections [$i] ['soct'] = $section->getsoct ();
					$sections [$i] ['diengiai'] = $section->getdiengiai ();
					$sections [$i] ['sotienvn'] = $sections [$i] ['sotienvn'] + $sotien;
					$sections [$i] [$tkco] = $sotien;
					$sections ['tc'][$tkco] = $sections ['tc'][$tkco] + $sotien;
					$sections ['tc']['tc'] = $sections ['tc']['tc'] + $sotien;
					unset ( $section );
				}
			}
		else
			while ( ($section = & $sectionsIterator->next ()) ) {
				$tkco = $section->gettkco ();
				if (strpos($tkco, $tk) ===0)
					{
					$i = $section->getidphieu ();	
					$tkno = $section->gettkno ();
					$sotien = $section->getsotienvn ();
					if (!in_array($tkno, $sections ['tk']))
						{
						$sections ['tk'][$k] =$tkno;
						$k += 1;
						}

					
					$sections [$i] ['ngct'] = $section->getngct ();
					$sections [$i] ['soct'] = $section->getsoct ();
					$sections [$i] ['diengiai'] = $section->getdiengiai ();
					$sections [$i] ['sotienvn'] = $sections [$i] ['sotienvn'] + $sotien;
					$sections [$i] [$tkno] = $sotien;
					$sections ['tc'][$tkno] = $sections ['tc'][$tkno] + $sotien;
					$sections ['tc']['tc'] = $sections ['tc']['tc'] + $sotien;
					
					unset ( $section );
					}
			}

		return $sections;
		
	}





function &getCTKHO_socai($journalid, $nam, $ngay1, $ngay2, $tk, $ectkt, $eCTKHO) {
	if ($ectkt && $eCTKHO)
	{
	$query = 	
	   "SELECT @s:=@s+1 stt,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (a.tk like '".$tk."%'  or b.tkdu like '".$tk."%' )
	union
	SELECT @s:=@s+1 stt, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (b.tkno like '".$tk."%'  or b.tkco like '".$tk."%' )
	   Order by ngct, soct, id";
	}
	elseif ($ectkt && !$eCTKHO)
		$query = 	
	   "SELECT @s:=@s+1 stt, '".$tk."' as tk,  a.soct, a.ngct, b.diengiai,  b.macttkdu as macttk, 
		CASE a.noco
		   WHEN 'N' THEN a.tk
		   WHEN 'C' THEN b.tkdu
		   END AS tkno,
	  CASE a.noco
		   WHEN 'N' THEN b.tkdu
		   WHEN 'C' THEN a.tk
		   END AS tkco,
		   b.sotienvn, b.id
	   FROM (SELECT @s:= 0) AS s , CTKT".$journalid. $nam . " a LEFT JOIN CTKTDT".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (a.tk like '".$tk."%'  or b.tkdu like '".$tk."%' )   Order by ngct, soct, id";
	  else if (!$ectkt && $eCTKHO)
	$query = 	
	   " SELECT @s:=@s+1 stt, '".$tk."' as tk, a.soct, a.ngct, b.diengiai, 'ktth' as macttkdu,  b.tkno, b.tkco,  b.sotienvn, b.idphieu as id
	   FROM (SELECT @s:= 0) AS s , CTKHO".$journalid. $nam . "  a LEFT JOIN CTKHOdt".$journalid. $nam . " b ON (a.idphieu = b.idphieu) WHERE (a.ngct BETWEEN '".$ngay1."' AND '".$ngay2."') and (b.tkno like '".$tk."%'  or b.tkco like '".$tk."%' )
	   Order by ngct, soct, id";

		$result = & $this->retrieve ( $query );

		$returner = new DAOResultFactory ( $result, $this, '_returnCTKHO_socai_FromRow' );
		return $returner;
	}


function &_returnCTKHO_socai_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO ->setidphieu($row['idphieu']);
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->setdiengiai($row['diengiai']);
		$CTKHO->setmacttk($row['macttk']);
		$CTKHO->settkno($row['tkno']);
		$CTKHO->settkco($row['tkco']);
		$CTKHO->settkdu($row['tkno'], $row['tkco'], $gctk);
		$CTKHO->settk($row['tk']);
		$CTKHO->setnoco($row['tkno'], $row['tkco'], $row['tk']);
		
		$CTKHO->setsotienvn($row['sotienvn']);

		return $CTKHO;
	}

function &getCTKHO_socai_PSDK_TMTG($journalid, $nam, $ngay1, $ngay2, $tk) {

		$query =   "SELECT sum(if(
		(noco = 'N' && tk like '".$tk."%') or (noco = 'C' && tkdu like '".$tk."%'),  b.sotienvn,0)) as psnovn, sum(if(
		(noco = 'C' and tk like '".$tk."%') or (noco = 'N' && tkdu like '".$tk."%'),
		b.sotienvn,0)) as pscovn FROM CTKT".$journalid. $nam."  a LEFT JOIN ctktdt".$journalid. $nam . " b  ON (a.idphieu = b.idphieu)  WHERE DATE( a.ngct ) < '". $ngay1.  "'";

		$result = & $this->retrieve ( $query );
		$result=$result->GetRowAssoc(false);
		return $result;

}

function &getCTKHO_socai_PSDK_KTTH($journalid, $nam, $ngay1, $ngay2, $tk) {

		$query =   "SELECT sum(if(
		tkno like '".$tk."%',  b.sotienvn,0)) as psnovn, sum(if(
		tkco like '".$tk."%', b.sotienvn,0)) as pscovn FROM CTKHO".$journalid. $nam."  a LEFT JOIN CTKHOdt".$journalid. $nam . " b  ON (a.idphieu = b.idphieu)  WHERE DATE( a.ngct ) < '". $ngay1.  "' ";

		$result = & $this->retrieve ( $query );
		$result=$result->GetRowAssoc(false);
		return $result;

}


function &getCTKHO_socai_SDDK($journalid, $nam, $ngay1, $ngay2, $tk) {
		$sections = $returner;
		$query = "SELECT sum(dknovn) as dknovn, sum(dkcovn) as dkcovn FROM SDTK" .$journalid. $nam ;
		$query = $query . " WHERE MATK like '" . $tk . "%' ";
		$result = & $this->retrieve ( $query );
		$result=$result->GetRowAssoc(false);
		return $result;
}




	function &_returnCTKHO_BCTMTG_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO ->setidphieu($row['idphieu']);
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->setngayct($row['ngayct']);
		$CTKHO->sethoten($row['hoten']);
		$CTKHO->setdiachi($row['diachi']);
		$CTKHO->setlydo($row['lydo']);
		$CTKHO->setsolgctg($row['solgctg']);
		$CTKHO->setmant($row['mant']);
		$CTKHO->settigia($row['tigia']);
		$CTKHO->settk($row['tk']);
		$CTKHO->settkdu($row['tkdu']);
		$CTKHO->setmacttkdu($row['macttkdu']);
		$CTKHO->setsotienvn($row['sotienvn']);
		$CTKHO->setsotiennt($row['sotiennt']);
		$CTKHO->setdiengiai($row['diengiai']);
		$CTKHO->setnoco($row['noco']);
		//HookRegistry::call('CTKHODAO::_returnCTKHO_BCTMTG_FromRow', array(&$CTKHO, &$row));
		return $CTKHO;

	}


	function &getCTKHO_ThuChi($query) {
		$result = & $this->retrieve ( $query );
		$sections = $returner ;
		$i = 0;
		while (!$result->EOF) {
			$rows = $result->GetRowAssoc(false);
			$pmatk = $rows['matk'];
			$ptentk = $rows['tentk'];
			$sections[$pmatk."-".$ptentk] = $pmatk."-".$ptentk;

			if ($i==0)
			{
				$sections [0] ['ngct'] = $rows['ngct'] ;
				$sections [0] ['soct'] = $rows['soct'] ;
				$sections [0] ['hoten'] = $rows['hoten'] ;
				$sections [0] ['diachi'] = $rows['diachi'] ;
				$sections [0] ['lydo'] = $rows['lydo'] ;
				$sections [0] ['solgctg'] = $rows['solgctg'] ;
				$sections [0] ['tkdu'] = $rows['tkdu'] ;
				$sections [0] ['tk'] = $rows['tk'] ;
				$sections [0] ['sotienvn'] = floatval($rows['sotienvn']) ;
			}
			else
			{
				$sections [$i] ['tkdu'] = $rows['tkdu'];
				$cotkdu = 0;
				for ($x=0; $x <$i; $x++) {
					if ($sections [$i] ['tkdu'] != $sections [$x] ['tkdu'])
					{
						$cotkdu = 1;
					}
										
				} 
				if ($cotkdu == 1)
					$sections [0] ['tkdu'] .= "-" .  $rows['tkdu'];

				$sections [0] ['sotienvn'] += floatval($rows['sotienvn']) ;


			}
			$i += 1;

			unset($section);
			$result->moveNext();
		}
 	   return $sections;
	}

	function &_returnCTKHO_ThuChi_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO->setsoct($row['soct']);
		$CTKHO->setngct($row['ngct']);
		$CTKHO->sethoten($row['hoten']);
		$CTKHO->setdiachi($row['diachi']);
		$CTKHO->setlydo($row['lydo']);
		$CTKHO->setsolgctg($row['solgctg']);
		$CTKHO->settk($row['tk']);
		$CTKHO->settkdu($row['tkdu']);
		$CTKHO->setsotienvn($row['sotienvn']);
		return $CTKHO;

	}

	function &_returnSDTT_FromRow(&$row) {
		$CTKHO = new CTKHO();
		$CTKHO->setdknovn($row['dknovn']);
		$CTKHO->setdknont($row['dknont']);
				return $CTKHO;

	}

	
	function CreateTable($Year, $journalid ) {
		$sql = "CREATE TABLE CTKHO".$journalid.$Year." LIKE CTKHOstr" ;
		$result =& $this->retrieve($sql );
		$sql = "CREATE TABLE CTKHODT".$journalid.$Year." LIKE CTKHODTstr" ;
		$result =& $this->retrieve($sql );

		return;

	}



}

?>
